package com.edu.study.base.wordBook.controller;

import java.util.List;

import com.edu.study.base.wordBook.domain.WordBook;
import com.edu.study.base.wordBook.service.IWordBookService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 词书管理Controller
 * 
 * @author zw
 * @date 2022-04-11
 */
@RestController
@RequestMapping("/study/wordbook")
public class WordBookController extends BaseController
{
    @Autowired
    private IWordBookService wordBookService;

    /**
     * 查询词书管理列表
     */
    @PreAuthorize("@ss.hasPermi('study:wordbook:list')")
    @GetMapping("/list")
    public TableDataInfo list(WordBook wordBook)
    {
        startPage();
        List<WordBook> list = wordBookService.selectWordBookList(wordBook);
        return getDataTable(list);
    }

    /**
     * 导出词书管理列表
     */
    @PreAuthorize("@ss.hasPermi('study:wordbook:export')")
    @Log(title = "词书管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WordBook wordBook)
    {
        List<WordBook> list = wordBookService.selectWordBookList(wordBook);
        ExcelUtil<WordBook> util = new ExcelUtil<WordBook>(WordBook.class);
        return util.exportExcel(list, "wordbook");
    }

    /**
     * 获取词书管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('study:wordbook:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(wordBookService.selectWordBookById(id));
    }

    /**
     * 新增词书管理
     */
    @PreAuthorize("@ss.hasPermi('study:wordbook:add')")
    @Log(title = "词书管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WordBook wordBook)
    {
        return toAjax(wordBookService.insertWordBook(wordBook));
    }

    /**
     * 修改词书管理
     */
    @PreAuthorize("@ss.hasPermi('study:wordbook:edit')")
    @Log(title = "词书管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WordBook wordBook)
    {
        return toAjax(wordBookService.updateWordBook(wordBook));
    }

    /**
     * 删除词书管理
     */
    @PreAuthorize("@ss.hasPermi('study:wordbook:remove')")
    @Log(title = "词书管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wordBookService.deleteWordBookByIds(ids));
    }
}
